<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <a-row :gutter="24">
        <a-col
          :span="24 - gutter"
          v-if="deptFlag"
        >
          <!-- 部门树 -->
          <dept-tree
            ref="deptTree"
            :deptOptions="deptOptions"
            @select="clickDeptNode"
          />
        </a-col>
        <a-col :span="gutter">
          <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="48">
                <a-col
                  :md="8"
                  :sm="24"
                >
                  <a-form-item
                    label="状态"
                    prop="year"
                  >
                    <a-select v-model="queryParam.type" placeholder="请选择状态">
                      <a-select-option
                        key="1"
                        value="1"
                      >包含过期</a-select-option>
                      <a-select-option
                        key="2"
                        value="2"
                      >不包含过期</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col
                  :md="!advanced && 8 || 24"
                  :sm="24"
                >
                  <span
                    class="table-page-search-submitButtons"
                    :style="advanced && { float: 'right', overflow: 'hidden' } || {} "
                  >
                    <a-button
                      type="primary"
                      @click="handleQuery"
                    >
                      <a-icon type="search" />查询
                    </a-button>
                  </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <!-- 数据展示 -->
          <a-list
            :grid="{gutter: 16, xl: 4, lg: 3, md: 3, sm: 2, xs: 1}"
            style="margin: 0 -8px"
          >
            <a-list-item
              :key="item"
              v-for="item in list"
              style="padding: 0 8px"
            >
              <a-card>
                <a-card-meta :title="item.type">
                  <a-avatar
                    slot="avatar"
                    style="color: white; backgroundColor: #1890ff"
                  >{{item.type}}</a-avatar>
                </a-card-meta>
                <div class="content">
                  <div>
                    <p>剩余金额</p>
                    <p>{{item.value}}￥</p>
                  </div>
                </div>
              </a-card>
            </a-list-item>
          </a-list>
        </a-col>
      </a-row>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import storage from 'store'
import { getCardRemain } from '@/api/manager/perform'
import { tableMixin } from '@/store/table-mixin'
import { treeselect } from '@/api/system/dept'
import DeptTree from '../../system/user/modules/DeptTree'
import moment from 'moment'

export default {
  name: 'RemainCard',
  mixins: [tableMixin],
  components: {
    DeptTree,
  },
  data() {
    return {
      deptFlag: false,
      gutter: 24,
      deptId: null,
      rankList: [],
      visible: false,
      list: [],
      selectedRowKeys: [],
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      ids: [],
      loading: false,
      total: 0,
      // 查询参数
      queryParam: {},
      deptOptions: [],
    }
  },
  filters: {},
  created() {
    this.deptInit()
    this.getList()
    this.getTreeselect()
    this.deptId = storage.get('deptId')
  },
  computed: {},
  watch: {},
  methods: {
    deptInit() {
      this.deptFlag = storage.get('deptId') == 100
      this.queryParam.deptId = storage.get('deptId')
      if (this.queryParam.deptId == null) {
        this.queryParam.deptId = storage.get('deptId')
      }

      if (this.deptFlag) {
        this.gutter = 20
      } else {
        this.gutter = 24
      }
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then((response) => {
        this.deptOptions = response.data
      })
    },
    clickDeptNode(deptId) {
      this.queryParam.deptId = deptId
      this.handleQuery()
    },
    /** 查询校区业绩列表 */
    getList() {
      this.loading = true
      if (this.queryParam.deptId == null || this.queryParam.deptId < 100) {
        this.queryParam.deptId = storage.get('deptId')
      }
      getCardRemain(this.queryParam).then((response) => {
        this.list = response.data
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
  },
}
</script>
<style lang="less" scoped>
.clearfix() {
  zoom: 1;
  &:before,
  &:after {
    content: ' ';
    display: table;
  }
  &:after {
    clear: both;
    visibility: hidden;
    font-size: 0;
    height: 0;
  }
}
.content {
  .clearfix();
  margin-top: 16px;
  margin-left: 40px;
  & > div {
    position: relative;
    text-align: left;
    float: left;
    width: 50%;
    p {
      line-height: 32px;
      font-size: 24px;
      margin: 0;
    }
    p:first-child {
      color: 'rgba(0, 0, 0, 0.45)';
      font-size: 12px;
      line-height: 20px;
      margin-bottom: 4px;
    }
  }
}
</style>